import delimited "/Output_Updated.csv", delimiter(comma)

global controls shareofelderly65 shareofmalepopulation year
global healthcontrols averagehealth smokingprevalencein bmi30
global ginigdp gini gdppc gdppc2 
global education averageeducationlevel

encode country, gen(cntry)
xtset cntry year

**Generate country dummies
generate AT=0
replace AT=1 if cntry==1
generate BE=0
replace BE=1 if cntry==2
generate BG=0
replace BG=1 if cntry==3
generate CY=0
replace CY=1 if cntry==4
generate CZ=0
replace CZ=1 if cntry==5
generate DK=0
replace DK=1 if cntry==6
generate EE=0
replace EE=1 if cntry==7
generate FI=0
replace FI=1 if cntry==8
generate FR=0
replace FR=1 if cntry==9
generate DE=0
replace DE=1 if cntry==10
generate GR=0
replace GR=1 if cntry==11
generate HR=0
replace HR=1 if cntry==12
generate HU=0
replace HU=1 if cntry==13
generate IE=0
replace IE=1 if cntry==14
generate IL=0
replace IL=1 if cntry==15
generate IS=0
replace IS=1 if cntry==16
generate IT=0
replace IT=1 if cntry==17
generate LT=0
replace LT=1 if cntry==18
generate LV=0
replace LV=1 if cntry==19
generate NL=0
replace NL=1 if cntry==20
generate NO=0
replace NO=1 if cntry==21
generate PL=0
replace PL=1 if cntry==22
generate PT=0
replace PT=1 if cntry==23
generate RU=0
replace RU=1 if cntry==24
generate SK=0
replace SK=1 if cntry==25
generate SI=0
replace SI=1 if cntry==26
generate ES=0
replace ES=1 if cntry==27
generate SE=0
replace SE=1 if cntry==28
generate CH=0
replace CH=1 if cntry==29
generate UA=0
replace UA=1 if cntry==30

global countrydummies AT BE BG CY CZ DK EE FI FR DE GR HR HU IE IL IS IT LT LV NL NO PL PT RU SK SI ES SE CH UA

**COWELLDOWN IVREG (INSTRUMENT = Lagged Democracy Time_15 Years):
ivreg cowelldown $controls $countrydummies (democracytime = laggeddemocracytime15), cluster(country)
outreg2 using cowelldown_IVREG_country.doc, replace e(F r2 r2_a)

ivreg cowelldown $controls $countrydummies (democracytime = laggeddemocracytime15) pca, cluster(country)
outreg2 using cowelldown_IVREG_country.doc, append e(F r2 r2_a)

ivreg cowelldown $controls $countrydummies (democracytime = laggeddemocracytime15) pca $ginigdp, cluster(country)
outreg2 using cowelldown_IVREG_country.doc, append e(F r2 r2_a)

**COWELLUP IVREG (INSTRUMENT = Lagged Democracy Time_15 Years):
ivreg cowellup $controls $countrydummies (democracytime = laggeddemocracytime15), cluster(country)
outreg2 using cowellup_IVREG_country.doc, replace e(F r2 r2_a)

ivreg cowellup $controls $countrydummies (democracytime = laggeddemocracytime15) pca, cluster(country)
outreg2 using cowellup_IVREG_country.doc, append e(F r2 r2_a)

ivreg cowellup $controls $countrydummies (democracytime = laggeddemocracytime15) pca $ginigdp, cluster(country)
outreg2 using cowellup_IVREG_country.doc, append e(F r2 r2_a)

**CONINDEX IVREG (INSTRUMENT = Lagged Democracy Time_15 Years):
ivreg conindex $controls $countrydummies (democracytime = laggeddemocracytime15), cluster(country)
outreg2 using conindex_IVREG_country.doc, replace e(F r2 r2_a)

ivreg conindex $controls $countrydummies (democracytime = laggeddemocracytime15) pca, cluster(country)
outreg2 using conindex_IVREG_country.doc, append e(F r2 r2_a)

ivreg conindex $controls $countrydummies (democracytime = laggeddemocracytime15) pca $ginigdp, cluster(country)
outreg2 using conindex_IVREG_country.doc, append e(F r2 r2_a)

**COWELLDOWN OLS
reg cowelldown democracytime $controls $countrydummies, cluster(country)
outreg2 using cowelldown_OLS_country.doc, replace e(r2 r2_a)

reg cowelldown democracytime $controls $countrydummies pca, cluster(country)
outreg2 using cowelldown_OLS_country.doc, append e(r2 r2_a)

reg cowelldown democracytime $controls $countrydummies pca $ginigdp, cluster(country)
outreg2 using cowelldown_OLS_country.doc, append e(r2 r2_a)

**COWELLUP OLS
reg cowellup democracytime $controls $countrydummies, cluster(country)
outreg2 using cowellup_OLS_country.doc, replace e(r2 r2_a)

reg cowellup democracytime $controls $countrydummies pca, cluster(country)
outreg2 using cowellup_OLS_country.doc, append e(r2 r2_a)

reg cowellup democracytime $controls $countrydummies pca $ginigdp, cluster(country)
outreg2 using cowellup_OLS_country.doc, append e(r2 r2_a)

**CONINDEX OLS
reg conindex democracytime $controls $countrydummies, cluster(country)
outreg2 using conindex_OLS_country.xls, replace e(r2 r2_a)

reg conindex democracytime $controls $countrydummies pca, cluster(country)
outreg2 using conindex_OLS_country.xls, append e(r2 r2_a)

reg conindex democracytime $controls $countrydummies pca $ginigdp, cluster(country)
outreg2 using conindex_OLS_country.xls, append e(r2 r2_a)


**Generate regional dummies(central, east, northeast, north, south)
**CT: central, ET: east, NE: northeast, NT: north
generate CT=0
replace CT=1 if AT==1 | BE==1 | FR==1 | DE==1 | CH==1 | NL==1
generate ET=0
replace ET=1 if PL==1 | SK==1 | SI==1 | CZ==1 | HR==1 | HU==1 | RU==1 | UA==1 | BG==1
generate NE=0
replace NE=1 if EE==1 | LV==1 | LT==1
generate NT=0
replace NT=1 if DK==1 | FI==1 | NO==1 | SE==1 | IS==1 | IE==1 | cntry==31

global regionaldummies CT ET NE NT


**COWELLDOWN IVREG (INSTRUMENT = Lagged Democracy Time_15 Years):
ivreg cowelldown $controls $regionaldummies (democracytime = laggeddemocracytime15), cluster(country)
outreg2 using cowelldown_IVREG_region.doc, replace e(F r2 r2_a)

ivreg cowelldown $controls $regionaldummies (democracytime = laggeddemocracytime15) pca, cluster(country)
outreg2 using cowelldown_IVREG_region.doc, append e(F r2 r2_a)

ivreg cowelldown $controls $regionaldummies (democracytime = laggeddemocracytime15) pca $ginigdp, cluster(country)
outreg2 using cowelldown_IVREG_region.doc, append e(F r2 r2_a)

**COWELLUP IVREG (INSTRUMENT = Lagged Democracy Time_15 Years):
ivreg cowellup $controls $regionaldummies (democracytime = laggeddemocracytime15), cluster(country)
outreg2 using cowellup_IVREG_region.doc, replace e(F r2 r2_a)

ivreg cowellup $controls $regionaldummies (democracytime = laggeddemocracytime15) pca, cluster(country)
outreg2 using cowellup_IVREG_region.doc, append e(F r2 r2_a)

ivreg cowellup $controls $regionaldummies (democracytime = laggeddemocracytime15) pca $ginigdp, cluster(country)
outreg2 using cowellup_IVREG_region.doc, append e(F r2 r2_a)

**CONINDEX IVREG (INSTRUMENT = Lagged Democracy Time_15 Years):
ivreg conindex $controls $regionaldummies (democracytime = laggeddemocracytime15), cluster(country)
outreg2 using conindex_IVREG_region.doc, replace e(F r2 r2_a)

ivreg conindex $controls $regionaldummies (democracytime = laggeddemocracytime15) pca, cluster(country)
outreg2 using conindex_IVREG_region.doc, append e(F r2 r2_a)

ivreg conindex $controls $regionaldummies (democracytime = laggeddemocracytime15) pca $ginigdp, cluster(country)
outreg2 using conindex_IVREG_region.doc, append e(F r2 r2_a)

**COWELLDOWN OLS
reg cowelldown democracytime $controls $regionaldummies, cluster(country)
outreg2 using cowelldown_OLS_region.doc, replace e(r2 r2_a)

reg cowelldown democracytime $controls $regionaldummies pca, cluster(country)
outreg2 using cowelldown_OLS_region.doc, append e(r2 r2_a)

reg cowelldown democracytime $controls $regionaldummies pca $ginigdp, cluster(country)
outreg2 using cowelldown_OLS_region.doc, append e(r2 r2_a)

**COWELLUP OLS
reg cowellup democracytime $controls $regionaldummies, cluster(country)
outreg2 using cowellup_OLS_region.doc, replace e(r2 r2_a)

reg cowellup democracytime $controls $regionaldummies pca, cluster(country)
outreg2 using cowellup_OLS_region.doc, append e(r2 r2_a)

reg cowellup democracytime $controls $regionaldummies pca $ginigdp, cluster(country)
outreg2 using cowellup_OLS_region.doc, append e(r2 r2_a)

**CONINDEX OLS
reg conindex democracytime $controls $regionaldummies, cluster(country)
outreg2 using conindex_OLS_region.doc, replace e(r2 r2_a)

reg conindex democracytime $controls $regionaldummies pca, cluster(country)
outreg2 using conindex_OLS_region.doc, append e(r2 r2_a)

reg conindex democracytime $controls $regionaldummies pca $ginigdp, cluster(country)
outreg2 using conindex_OLS_region.doc, append e(r2 r2_a)